float4 ScreenSize=float4(1920,(1/1920),(1920/1080),(1080/1920));
float4 Timer;

static float FlipSize = ScreenSize.w*ScreenSize.x;
static float2 screenRes = {ScreenSize.x,FlipSize};


#define SEEDX			Timer.w	
#define PIX			3.1415926535897932384626433832795

#define fFlareHorizontal		1


//#include "effect_config.txt"

#include "enbseries_mastereffect.ini"
//--------------------------------------------------------------------------------------
// Textures
//--------------------------------------------------------------------------------------
texture2D texColor;
texture2D texDepth;
texture2D texNoise;

//--------------------------------------------------------------------------------------
// Sampler Inputs
//--------------------------------------------------------------------------------------


sampler2D InputSampler = sampler_state
{
    Texture = (texColor);
    MinFilter = POINT;
    MagFilter = POINT;
    MipFilter = POINT;
    AddressU   = Clamp;
	AddressV   = Clamp;
	SRGBTexture=FALSE;
	MaxMipLevel=0;
	MipMapLodBias=0;
};

sampler2D SamplerDepth = sampler_state
{
	Texture   = <texDepth>;
	MinFilter = POINT;
	MagFilter = POINT;
	MipFilter = NONE;
	AddressU  = Clamp;
	AddressV  = Clamp;
	SRGBTexture=FALSE;
	MaxMipLevel=0;
	MipMapLodBias=0;
};

sampler2D SamplerNoise = sampler_state
{
	Texture   = <texNoise>;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = LINEAR;
	AddressU  = Wrap;
	AddressV  = Wrap;
	SRGBTexture = FALSE;
	MaxMipLevel = 0;
	MipMapLodBias = 0;
};


struct VS_OUTPUT_POST {
 float4 vpos  : POSITION;
 float2 txcoord : TEXCOORD0;
};

struct VS_INPUT_POST {
 float3 pos  : POSITION;
 float2 txcoord : TEXCOORD0;
};

float pixelWidth;
float pixelHeight;


//--------------------------------------------------------------------------------------
// Vertex Shader Input
//--------------------------------------------------------------------------------------

VS_OUTPUT_POST VS_PostProcess(VS_INPUT_POST IN)
{
 VS_OUTPUT_POST OUT;

 float4 pos=float4(IN.pos.x,IN.pos.y,IN.pos.z,1.0);

 OUT.vpos=pos;
 OUT.txcoord.xy=IN.txcoord.xy;

 return OUT;
}


//--------------------------------------------------------------------------------------
// Helpers
//--------------------------------------------------------------------------------------

#include "effect_functions.txt"




//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------


float4 FxaaPixelShader(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR
{

#define FxaaTexTop(t, p) tex2Dlod(t, float4(p, 0.0, 0.0))
#define FxaaTexOff(t, p, o, r) tex2Dlod(t, float4(p + (o * r), 0, 0))

float2 pos = IN.txcoord.xy;

float2 rcpFrame = float2(1/ScreenSize.x, ScreenSize.z/ScreenSize.x);
float4 rcpFrameOpt = float4(2/ScreenSize.x, 2*ScreenSize.z/ScreenSize.x, 0.5/ScreenSize.x, 0.5*ScreenSize.z/ScreenSize.x);

float lumaN = dot(FxaaTexOff(InputSampler, pos.xy, float2(0, -1), rcpFrame.xy).xyz, float3(0.299, 0.587, 0.114));
float lumaW = dot(FxaaTexOff(InputSampler, pos.xy, float2(-1, 0), rcpFrame.xy).xyz, float3(0.299, 0.587, 0.114));


float4 rgbyM;
rgbyM.xyz = FxaaTexTop(InputSampler, pos.xy).xyz;
rgbyM.w = dot(rgbyM.xyz, float3(0.299, 0.587, 0.114));
float lumaE = dot(FxaaTexOff(InputSampler, pos.xy, float2( 1, 0), rcpFrame.xy).xyz, float3(0.299, 0.587, 0.114));
float lumaS = dot(FxaaTexOff(InputSampler, pos.xy, float2( 0, 1), rcpFrame.xy).xyz, float3(0.299, 0.587, 0.114));
float lumaM = rgbyM.w;


float rangeMin = min(lumaM, min(min(lumaN, lumaW), min(lumaS, lumaE)));
float rangeMax = max(lumaM, max(max(lumaN, lumaW), max(lumaS, lumaE)));
float range = rangeMax - rangeMin;

if(range < max(FXAA_QUALITY__EDGE_THRESHOLD_MIN, rangeMax * FXAA_QUALITY__EDGE_THRESHOLD)) return rgbyM;


float lumaNW = dot(FxaaTexOff(InputSampler, pos.xy, float2(-1,-1), rcpFrame.xy).xyz, float3(0.299, 0.587, 0.114));
float lumaNE = dot(FxaaTexOff(InputSampler, pos.xy, float2( 1,-1), rcpFrame.xy).xyz, float3(0.299, 0.587, 0.114));
float lumaSW = dot(FxaaTexOff(InputSampler, pos.xy, float2(-1, 1), rcpFrame.xy).xyz, float3(0.299, 0.587, 0.114));
float lumaSE = dot(FxaaTexOff(InputSampler, pos.xy, float2( 1, 1), rcpFrame.xy).xyz, float3(0.299, 0.587, 0.114));



float lumaL = (lumaN + lumaW + lumaE + lumaS) * 0.25;
float rangeL = abs(lumaL - lumaM);
float blendL = saturate((rangeL / range) - FXAA_QUALITY__SUBPIX_TRIM) * FXAA_QUALITY__SUBPIX_TRIM_SCALE;
blendL = min(FXAA_QUALITY__SUBPIX_CAP, blendL);

float edgeVert = abs(lumaNW + (-2.0 * lumaN) + lumaNE) + 2.0 * abs(lumaW + (-2.0 * lumaM) + lumaE ) + abs(lumaSW + (-2.0 * lumaS) + lumaSE);
float edgeHorz = abs(lumaNW + (-2.0 * lumaW) + lumaSW) + 2.0 * abs(lumaN + (-2.0 * lumaM) + lumaS ) + abs(lumaNE + (-2.0 * lumaE) + lumaSE);
bool horzSpan = edgeHorz >= edgeVert;

float lengthSign = horzSpan ? -rcpFrame.y : -rcpFrame.x;
if(!horzSpan) lumaN = lumaW;
if(!horzSpan) lumaS = lumaE;
float gradientN = abs(lumaN - lumaM);
float gradientS = abs(lumaS - lumaM);
lumaN = (lumaN + lumaM) * 0.5;
lumaS = (lumaS + lumaM) * 0.5;

bool pairN = gradientN >= gradientS;
if(!pairN) lumaN = lumaS;
if(!pairN) gradientN = gradientS;
if(!pairN) lengthSign *= -1.0;
float2 posN;
posN.x = pos.x + (horzSpan ? 0.0 : lengthSign * 0.5);
posN.y = pos.y + (horzSpan ? lengthSign * 0.5 : 0.0);


gradientN *= FXAA_SEARCH_THRESHOLD;

float2 posP = posN;
float2 offNP = horzSpan ?
float2(rcpFrame.x, 0.0) :
float2(0.0f, rcpFrame.y);
float lumaEndN;
float lumaEndP;
bool doneN = false;
bool doneP = false;
posN += offNP * (-1.5);
posP += offNP * ( 1.5);
for(int i = 0; i < FXAA_SEARCH_STEPS; i++)
{
lumaEndN = dot(FxaaTexTop(InputSampler, posN.xy).xyz, float3(0.299, 0.587, 0.114));
lumaEndP = dot(FxaaTexTop(InputSampler, posP.xy).xyz, float3(0.299, 0.587, 0.114));
bool doneN2 = abs(lumaEndN - lumaN) >= gradientN;
bool doneP2 = abs(lumaEndP - lumaN) >= gradientN;
if(doneN2 && !doneN) posN += offNP;
if(doneP2 && !doneP) posP -= offNP;
if(doneN2 && doneP2) break;
doneN = doneN2;
doneP = doneP2;
if(!doneN) posN -= offNP * 2.0;
if(!doneP) posP += offNP * 2.0;
}

float dstN = horzSpan ? pos.x - posN.x : pos.y - posN.y;
float dstP = horzSpan ? posP.x - pos.x : posP.y - pos.y;

bool directionN = dstN < dstP;
lumaEndN = directionN ? lumaEndN : lumaEndP;

if(((lumaM - lumaN) < 0.0) == ((lumaEndN - lumaN) < 0.0))
lengthSign = 0.0;

float spanLength = (dstP + dstN);
dstN = directionN ? dstN : dstP;
float subPixelOffset = 0.5 + (dstN * (-1.0/spanLength));
subPixelOffset += blendL * (1.0/8.0);
subPixelOffset *= lengthSign;
float3 rgbF = FxaaTexTop(InputSampler, float2(pos.x + (horzSpan ? 0.0 : subPixelOffset), pos.y + (horzSpan ? subPixelOffset : 0.0))).xyz;

#if (FXAA_LINEAR == 1)
lumaL *= lumaL;
#endif
float lumaF = dot(rgbF, float3(0.299, 0.587, 0.114)) + (1.0/(65536.0*256.0));
float lumaB = lerp(lumaF, lumaL, blendL);
float scale = min(4.0, lumaB/lumaF);
rgbF *= scale;


//rgbF/= 3;

return float4(rgbF, lumaM);
}



float4 Tonemap(VS_OUTPUT_POST i, float2 vPos : VPOS) : COLOR
{


float2 fvTexelSizeBloom = float2(1.0 / 1920, 1.0 / 1080);


#if (SHARPEN==1)
float4 color = 9 * tex2D(InputSampler, i.txcoord);
color -= tex2D(InputSampler, i.txcoord.xy + float2(-fvTexelSizeBloom.x, fvTexelSizeBloom.y) * fSharpScale);
color -= tex2D(InputSampler, i.txcoord.xy + float2(0.0, fvTexelSizeBloom.y) * fSharpScale);
color -= tex2D(InputSampler, i.txcoord.xy + float2(fvTexelSizeBloom.x, fvTexelSizeBloom.y) * fSharpScale);
color -= tex2D(InputSampler, i.txcoord.xy + float2(fvTexelSizeBloom.x, 0.0) * fSharpScale);
color -= tex2D(InputSampler, i.txcoord.xy + float2(fvTexelSizeBloom.x, -fvTexelSizeBloom.y) * fSharpScale);
color -= tex2D(InputSampler, i.txcoord.xy + float2(0.0, -fvTexelSizeBloom.y) * fSharpScale);
color -= tex2D(InputSampler, i.txcoord.xy + float2(-fvTexelSizeBloom.x, -fvTexelSizeBloom.y) * fSharpScale);
color -= tex2D(InputSampler, i.txcoord.xy + float2(-fvTexelSizeBloom.x, 0.0) * fSharpScale);
#endif

#if (SHARPEN==0)
float4 color = tex2D(InputSampler, i.txcoord);
#endif


#if(BLOOM_CRISP==1)
float steps = EBloomSteps;

float4 bloomcolor= 0;
fvTexelSizeBloom *= EBloomRadius;	
float2 direction;
 
for(float x = 1; x<=steps; x++)
{
	
direction=float2(-0.707, 0.707) * 1.282*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(-0.383, 0.924) * 1.282*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(0.0, 1.0) * 1.282*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(0.383, 0.924) * 1.282*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(0.707, 0.707) * 1.282*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(-0.924, 0.383) * 1.282*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(-0.707, 0.707) * 0.524*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(0.0, 1.0) * 0.524*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(0.707, 0.707) * 0.524*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(0.924, 0.383) * 1.282*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(-1.0, 0.0) * 1.282*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(-1.0, 0.0) * 0.524*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(0.0, 0.0)*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(1.0, 0.0) * 0.524*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(1.0, 0.0) * 1.282*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(-0.924, -0.383) * 1.282*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(-0.707, -0.707) * 0.524*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(0.0, -1.0) * 0.524*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(0.707, -0.707) * 0.524*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(0.924, -0.383) * 1.282*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(-0.707, -0.707) * 1.282*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(-0.383, -0.924) * 1.282*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(0.0, -1.0) * 1.282*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(0.383, -0.924) * 1.282*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(0.707, -0.707) * 1.282*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
}
bloomcolor /= 25*steps;

bloomcolor *= bloomcolor*EBloomCurve;

float sVal = EBloomSat;
float sLuma = dot(bloomcolor.xyz,float3(0.27, 0.67, 0.06));
float3 sNcolor = normalize(bloomcolor);
sNcolor.xyz = pow(sNcolor.xyz, sVal);
float sNluma = dot(sNcolor.xyz,float3(0.27, 0.67, 0.06));
bloomcolor.xyz = sNcolor.xyz*sLuma/sNluma;




color += bloomcolor*EBloomAmount;

#endif

	 
#if (SKYRIMTONEMAP==1)

float4	Adaptation=float4( 0.0, 0.0, 0.0, 1 );
float	grayadaptation = Luminance(color);

#if (POSTPROCESS==1)

	grayadaptation = max(grayadaptation, 0.0);
	grayadaptation = min(grayadaptation, 50.0);
	color.xyz =  color.xyz / (grayadaptation * EAdaptationMaxV1 + EAdaptationMinV1);
		
	float cgray = dot( color.xyz, float3(0.27, 0.67, 0.06));
	cgray = pow(cgray, EContrastV1);
	float3 poweredcolor = pow( color.xyz, EColorSaturationV1);
	float newgray = dot(poweredcolor.xyz, float3(0.27, 0.67, 0.06));
	 color.xyz = poweredcolor.xyz * cgray / (newgray + 0.0001);

	float3	luma =  color.xyz;
	float	lumamax = 300.0;
	 color.xyz = ( color.xyz * (1.0 +  color.xyz / lumamax)) / ( color.xyz + EToneMappingCurveV1);	
#endif


#if (POSTPROCESS==2)

	grayadaptation = max(grayadaptation, 0.0);
	grayadaptation = min(grayadaptation, 50.0);
	 color.xyz =  color.xyz / (grayadaptation * EAdaptationMaxV2 + EAdaptationMinV2);
	float3 xncol = normalize( color.xyz);
	float3 scl =  color.xyz / xncol.xyz;
	scl = pow(scl, EIntensityContrastV2);
	xncol.xyz = pow(xncol.xyz, EColorSaturationV2);
	 color.xyz = scl*xncol.xyz;
	float	lumamax = EToneMappingOversaturationV2;
	 color.xyz = ( color.xyz * (1.0 +  color.xyz / lumamax)) / ( color.xyz + EToneMappingCurveV2);
 color.xyz*=4;

#endif


#if (POSTPROCESS==3)
	 color.xyz *= 35;
	float	lumamax = EToneMappingOversaturationV3;
	 color.xyz = ( color.xyz * (1.0 +  color.xyz / lumamax)) / ( color.xyz + EToneMappingCurveV3);
#endif


#if (POSTPROCESS == 4)
	grayadaptation = max(grayadaptation, 0.0);
	grayadaptation = min(grayadaptation, 50.0);
	 color.xyz =  color.xyz / (grayadaptation * EAdaptationMaxV4 + EAdaptationMinV4);

	float Y = dot( color.xyz, float3(0.299, 0.587, 0.114)); //0.299 * R + 0.587 * G + 0.114 * B;
	float U = dot( color.xyz, float3(-0.14713, -0.28886, 0.436)); //-0.14713 * R - 0.28886 * G + 0.436 * B;
	float V = dot( color.xyz, float3(0.615, -0.51499, -0.10001)); //0.615 * R - 0.51499 * G - 0.10001 * B;
		
	Y = pow(Y, EBrightnessCurveV4);
	Y = Y * EBrightnessMultiplierV4;
	 color.xyz = V * float3(1.13983, -0.58060, 0.0) + U * float3(0.0, -0.39465, 2.03211) + Y;
	 color.xyz = max( color.xyz, 0.0);
	 color.xyz =  color.xyz / ( color.xyz + EBrightnessToneMappingCurveV4);
#endif


#if (POSTPROCESS == 5)
	float hnd = 1;
	float2 hndtweak = float2( 3.1 , 1.5 );
	grayadaptation = max(grayadaptation, 0.0);
	grayadaptation = min(grayadaptation, 50.0);
	 color.xyz *= lerp( hndtweak.x, hndtweak.y, hnd );
	float3 xncol = normalize( color.xyz);
	float3 scl =  color.xyz/xncol.xyz;
	scl = pow(scl, EIntensityContrastV5);
	xncol.xyz = pow(xncol.xyz, EColorSaturationV5);
	 color.xyz = scl*xncol.xyz;
	 color.xyz *= HCompensateSatV5; // compensate for darkening caused my EcolorSat above
	 color.xyz =  color.xyz / ( color.xyz + EToneMappingCurveV5);
	 color.xyz *= 4;
#endif

#if (POSTPROCESS==6)
//Postprocessing V6 by Kermles
		//hd6/ppv2///////////////////////////////////////////
		float 	EIntensityContrastV6 = EIntensityContrastV6Day;
		float 	EColorSaturationV6 = EColorSaturationV6Day;
		float 	HCompensateSatV6 = HCompensateSatV6Day;
		float 	EToneMappingCurveV6 = EToneMappingCurveV6Day;
		float 	EBrightnessV6 = EBrightnessV6Day;
		float 	EToneMappingOversaturationV6 = EToneMappingOversaturationV6Day;
		float 	EAdaptationMaxV6 = EAdaptationMaxV6Day;
		float 	EAdaptationMinV6 = EAdaptationMinV6Day;
		float	lumamax = EToneMappingOversaturationV6;
		//kermles////////////////////////////////////////////
		float 	EAdaptationCompensateV6 = EAdaptationCompensateV6Day;
		float 	EBrightnessMaxV6 = EBrightnessMaxV6Day;
		float 	EBrightnessMinV6 = EBrightnessMinV6Day;
		float3 	moodColor = EMoodColorDay;
		float 	moodAmount = EMoodAmountDay;
		float 	moodCurve = EMoodCurveDay;
		float3 	shadowColor = EShadowColorDay;
		float 	shadowThreshold = EShadowThresholdDay;
		float 	shadowCurve = EShadowCurveDay;
		float3	brightSpotColor = EBrightSpotColorDay;
		float	brightSpotThreshold = EBrightSpotThresholdDay;
		float 	brightSpotCurve = EBrightSpotCurveDay / 10;
		float 	hsvDesatCurve = EHSVDesatCurveDay;
		float 	PPAmount = 0.5;				//controls interpolation between vanilla colors and PP6 colors	
		float4 	ncolor;					//temporary variable for color adjustments
		float 	avgbr;					//temporary variable for color adjustments
		
	//begin pp code/////////////////////////////////////////////////
		//store vanilla colors//////////////////////////////////////////
		float4 oldcolor =  color;
		//convert to hsv////////////////////////////////////////////////
		float3 hsvncolor = RGBtoHSV(  color.xyz );
		hsvncolor.y = max( hsvncolor.y, 0.0 );
		hsvncolor.z = max( hsvncolor.z, 0.0 );
		//desaturate based on original saturation then resaturate///////
		hsvncolor.y = pow( hsvncolor.y, hsvDesatCurve );
		hsvncolor.y = saturate(hsvncolor.y * EColorSaturationV6);
		//convert back to rgb///////////////////////////////////////////
		hsvncolor.y = max( hsvncolor.y, 0.0 );
		 color.xyz = HSVtoRGB( hsvncolor );
		//brightness clamping///////////////////////////////////////////
		 color.xyz=clamp( color.xyz, EBrightnessMinV6, EBrightnessMaxV6); 
		//ppv2 modified by kermles//////////////////////////////////////
		
		grayadaptation = clamp(grayadaptation, 0, 50);
		 color.xyz *= EBrightnessV6;
		float3 xncol = normalize( color.xyz);
		float3 scl =  color.xyz/xncol.xyz;
		scl = pow(scl, EIntensityContrastV6);
		xncol.xyz = pow(xncol.xyz, EColorSaturationV6);
		 color.xyz = scl*xncol.xyz;
		 color.xyz *= HCompensateSatV6;
		 color.xyz = ( color.xyz * (1.0 +  color.xyz/lumamax))/( color.xyz + EToneMappingCurveV6);
		//mood coloring/////////////////////////////////////////////////
		ncolor =  color;
		avgbr = (ncolor.x + ncolor.y + ncolor.z)/3;
		moodColor.xyz = lerp( moodColor/10, moodColor, saturate( avgbr * 2 ) );
		moodColor.xyz = lerp( moodColor, 1, saturate( avgbr - 0.5 ) * 2 );
		moodColor.xyz = lerp( ncolor, moodColor, saturate(avgbr / moodCurve));
		ncolor.xyz = lerp( ncolor, moodColor, saturate( avgbr * moodAmount ) );
		 color.xyz = max(0, ncolor);
		//shadows///////////////////////////////////////////////////////
		ncolor =  color;
		avgbr = (ncolor.x + ncolor.y + ncolor.z)/3;
		shadowColor = lerp(0.1*(2.55-shadowColor), 2.55-shadowColor, saturate(avgbr*2));
		shadowColor = lerp(shadowColor, 1, saturate(avgbr-0.5)*2);
		ncolor.xyz = max(ncolor, pow(ncolor, ((1.0+ncolor) * (shadowColor))*shadowThreshold)/shadowCurve);
		 color.xyz = saturate(ncolor);
		//brightspots///////////////////////////////////////////////////
		brightSpotColor = lerp(brightSpotColor/10, brightSpotColor, saturate(avgbr*2));
		brightSpotColor = lerp(brightSpotColor, 1, saturate(avgbr-0.5)*2);
		ncolor = 1- color;
		ncolor.xyz = max(ncolor, pow(ncolor, ((1.0 + ncolor) * (brightSpotColor))*brightSpotThreshold)/brightSpotCurve);
		 color.xyz = saturate(1-ncolor);
		//convert to hsv////////////////////////////////////////////////
		hsvncolor = RGBtoHSV(  color.xyz );
		hsvncolor.y = max( hsvncolor.y, 0.0 );
		hsvncolor.z = max( hsvncolor.z, 0.0 );
		//adaptation/contrast///////////////////////////////////////////
		hsvncolor.z = pow(hsvncolor.z, (grayadaptation*EAdaptationMaxV6+EAdaptationMinV6));
		//convert back to rgb///////////////////////////////////////////
		hsvncolor.y = max( hsvncolor.y, 0.0 );
		hsvncolor.z = max( hsvncolor.z, 0.0 );
		 color.xyz = HSVtoRGB( hsvncolor );
		 color.xyz /= grayadaptation*EAdaptationMaxV6+EAdaptationMinV6;
		 color.xyz /= EAdaptationCompensateV6;
		//rerun ppv2////////////////////////////////////////////////////
		 color.xyz *= EBrightnessV6;
		xncol = normalize( color.xyz);
		scl =  color.xyz/xncol.xyz;
		scl = pow(scl, EIntensityContrastV6);
		xncol.xyz = pow(xncol.xyz, EColorSaturationV6);
		 color.xyz = scl*xncol.xyz;
		 color.xyz *= HCompensateSatV6;
		 color.xyz = ( color.xyz * (1.0 +  color.xyz/lumamax))/( color.xyz + EToneMappingCurveV6);
		//lerp between vanilla and pp6 colors///////////////////////////
		 color = lerp(oldcolor,  color, PPAmount);

#endif
#endif

#define const_1 (DARK_LEVEL/255.0)
#define const_2 (255.0/(255.0-BRIGHT_LEVEL))

#if (TVLEVELS==1)
color.xyz = (color.xyz  - const_1) * const_2;
#endif

#if (COLORWASHOUT==1)
float	colorGray=dot(color.xyz, 0.333);
float	colorGray2=(colorGray*(6.2*colorGray+0.5))/(colorGray*(6.2*colorGray+1.7)+0.06);
float	colorGray3=pow(colorGray, 0.36);
float	colorWashout=saturate(colorGray2 - ColorWashoutThreshold)/(1.00 - ColorWashoutThreshold);
colorWashout=saturate(pow(colorWashout, ColorWashoutPow) * ColorWashoutAmount);

float3	middleColor=(color.xyz+0.0001)/(colorGray+0.000001);
middleColor.xyz=lerp(pow(middleColor.xyz, ColorSaturation), middleColor.xyz, ColorSaturation);
middleColor.xyz=lerp(middleColor.xyz, 1.00, saturate(colorWashout*ColorWashoutAmount));
float tonemapMix=(0.5 - ColorDullnessAmount)*0.60; //temp
	colorGray=lerp(colorGray2, colorGray3, tonemapMix);
	color.xyz=middleColor.xyz*colorGray;
color.xyz *= ExpAdjustment;
#endif

#if (VIBRANCEPASS==1)
float3 lumCoeff = float3(0.2126, 0.7152, 0.0722);
float vibranceluma = dot(lumCoeff, color.xyz);

float max_color = max(color.x, max(color.y,color.z)); //Find the strongest color
float min_color = min(color.x, max(color.y,color.z)); //Find the weakest color
float color_saturation = max_color - min_color;

color.xyz = lerp(vibranceluma, color.xyz, (1.0 + (Vibrance * (1.0 - (sign(Vibrance) * color_saturation)))));
#endif

#if (HDR==1)
color = TonemapPass(color);
#endif

#if (FILMICPASS==1)
color = FilmPass(color);
#endif

#if (CROSSPROCESS==1)
color = CrossProcess_PS(color);
#endif

#if (COLORMOOD==1)
color = MoodPass(color);
#endif


#if (SEPIA==1)
color = SepiaPass(color);
#endif

#if(COLORBOOST==1)
float Zmiddlegray=(color.r+color.g+color.b)*0.333;
float3 Zdiffcolor=color.rgb-Zmiddlegray;
color.rgb+=Zdiffcolor*0.6;
color.rgb-=Zdiffcolor*0.1;
#endif

#if (FINALADJUSTER==1)
color = FinalAdjusterPass(color);
#endif


#if (SPLITSCREEN==1)
return (i.txcoord.x < 0.5) ? tex2D(InputSampler, i.txcoord) : color;
#endif


color.w=1;

    return color; 
}


#if (DOF==1)
float4 PS_ProcessDoFBokeh(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR 
{
	float depth = linearize(tex2D(SamplerDepth,IN.txcoord.xy).x);

		
	float fDepth = focalDepth;
	
	#ifdef DoF_Auto
		fDepth = linearize(tex2D(SamplerDepth,focus).x);
	#endif
	
	float blur = 2.0;
	#ifdef DoF_Manual
		float a = depth-fDepth; //focal plane
		float b = (a-fdofstart)/fdofdist; //far DoF
		float c = (-a-ndofstart)/ndofdist; //near Dof
		blur = (a>0.0)?b:c;
	#else
		float f = focalLength; //focal length in mm
		float d = fDepth*1000.0; //focal plane in mm
		float o = depth*1000.0; //depth in mm
		
		float a = (o*f)/(o-f); 
		float b = (d*f)/(d-f); 
		float c = (d-f)/(d*fstop*CoC); 
		
		blur = abs(a-b)*c;
	#endif
	blur = saturate(blur);
	float2 noise = rand(IN.txcoord.xy)*namount*blur;
	
	float w = (1.0/screenRes.x)*blur*maxblur+noise.x;
	float h = (1.0/screenRes.y)*blur*maxblur+noise.y;
	
	float4 col = float4(0,0,0,1);
	
	if(blur < 0.05) //some optimization thingy
	{
		col = tex2D(InputSampler, IN.txcoord.xy);
	}
	else
	{
	col = tex2D(InputSampler, IN.txcoord.xy);
	float s = 1.0;
	int ringsamples;
	for (int i = 1; i <= rings; i += 1)
	{
		ringsamples = i * samples;
		for (int j = 0 ; j < ringsamples ; j += 1)
		{
			float step = PI*2.0 / ringsamples;
			float pw = cos(j*step)*i;
			float ph = sin(j*step)*i;
			float p = 1.0;
			#ifdef DoF_PentagonShape 
				p = penta(float2(pw,ph));
			#endif
			col.xyz += colorDof(IN.txcoord.xy + float2(pw*w,ph*h),blur).xyz;  
			s += 1.0*lerp(1.0,i/rings,bias)*p;
		}
	}
	col = col/s; //divide by sample count
	}
	
	#ifdef DoF_Vignetting
		col *= vignette(IN.txcoord.xy,vignint);
	#endif

#if (SPLITSCREEN==1)
return (IN.txcoord.x < 0.5) ? tex2D(InputSampler, IN.txcoord) : col;
#endif
	
	return col;
}
#endif






float4 Flares(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR
{

float4	res;

#if (CHROMATICABBERATION==0)
   float3	origcolor=tex2D(InputSampler, IN.txcoord.xy);
#endif

#if (CHROMATICABBERATION==1)
float4 coord=0.0;
coord.xy=IN.txcoord.xy;
coord.w=0.0;  
float3 eta = float3(1.0+ChromaticAmount*0.9,1.0+ChromaticAmount*0.6,1.0+ChromaticAmount*0.3);
float2 center;
center.x = coord.x-0.5;
center.y = coord.y-0.5;
float LensZoom = 1.0/LensSize;

float r2 = (IN.txcoord.x-0.5) * (IN.txcoord.x-0.5) + (IN.txcoord.y-0.5) * (IN.txcoord.y-0.5);     
float f = 0;

if( LensDistortionCubic == 0.0){
	f = 1 + r2 * LensDistortion;
}else{
                f = 1 + r2 * (LensDistortion + LensDistortionCubic * sqrt(r2));
};

float x = f*LensZoom*(coord.x-0.5)+0.5;
float y = f*LensZoom*(coord.y-0.5)+0.5;
float2 rCoords = (f*eta.r)*LensZoom*(center.xy*0.5)+0.5;
float2 gCoords = (f*eta.g)*LensZoom*(center.xy*0.5)+0.5;
float2 bCoords = (f*eta.b)*LensZoom*(center.xy*0.5)+0.5;

float4 inputDistord = float4(tex2D(InputSampler,rCoords).r , tex2D(InputSampler,gCoords).g ,tex2D(InputSampler,bCoords).b, tex2D(InputSampler,float2(x,y)).a);

float4 schmotzcolor = float4(inputDistord.r,inputDistord.g,inputDistord.b,1);

float3 origcolor = schmotzcolor.xyz;
 
#endif



#if (LENZ==1)
float3	lenz=0;
	float2	lenzuv=0.0;
	
	const float3 offset[15]=
	{
		float3(0.3, 0.01, 4),
		float3(0.7, 0.25, 25),
		float3(0.3, 0.25, 15),
// Full
		float3(1, 1.0, 5),
// Arriere
		float3(-0.15, 20, 1),
		float3(-0.3, 20, 1),
// Avant
		float3(0.5, 0.1, 1),
		float3(0.01, 10, 1),
		float3(20, 0.25, 1),
		float3(1000, 5, 100),
//Plein ecran passe inverse
		float3(0.5, -0.5, 2),
//Rond bleu du debut
		float3(2, 2, -5),
//2eme partie de la passe FS
		float3(-5, 0.2, 0.2),
//Derniere passe
		float3(0.15, 0.5, 20),
		float3(0.4, 1, 10)
	};

const float3 factors[15]=
	{
		float3(0.5, 0.5, 0),
		float3(0, 0.5, 0),
		float3(0, 0, 0.5),
// Full
		float3(0.2, 0.25, 0),
// Arriere
		float3(0.15, 0, 0.0),
		float3(0, 0.0, 0.15),
// Avant
		float3(0.2, 0.2, 0.05),
		float3(0.25, 0.25, 0.25),
		float3(1, 1, 1),
		float3(0, 0.25, 1),
//Plein ecran
		float3(0, 0,0.25),
//Rond bleu au debut
		float3(0, 0, 1),
//Derniere passe avec passe full combine
		float3(2, 2, 2),
		float3(1, 1, 0.25),
		float3(0, 0, 0)

	};


	for (int i=0; i<15; i++)
	{
		float2 distfact=(IN.txcoord.xy-0.5);
		lenzuv.xy=offset[i].x*distfact;
		lenzuv.xy*=pow(2.0*length(float2(distfact.x*ScreenSize.z,distfact.y)), offset[i].y);
		lenzuv.xy*=offset[i].z*0.5;
		lenzuv.xy=0.5-lenzuv.xy;
		float3 templenz=sampleblurred(lenzuv.xy);
		templenz=templenz*factors[i];
		distfact=(lenzuv.xy-0.5);
		distfact*=2.0;
		templenz*=saturate(1.0-dot(distfact,distfact));
		float maxlenz=max(templenz.x, max(templenz.y, templenz.z));
		float tempnor=(maxlenz/(1.0+maxlenz));
		tempnor=pow(tempnor, ELenzPower);
		templenz.xyz*=tempnor;
		lenz+=templenz;
	}


	lenz.xyz*=1.25*ELenzIntensity;

	res.xyz=origcolor + lenz;
#endif
#if (LENZ==0)
res.xyz=origcolor.xyz;
#endif


res.w=1.0;
return res;
}


#if (MATSO_FLARE==1)
float4 PS_ProcessPass_Anamorphic(VS_OUTPUT_POST IN, float2 vPos : VPOS, uniform int axis) : COLOR
{
	float4 res;
	float2 coord = IN.txcoord.xy;
	

#ifdef fFlareHorizontal
	#define fFlareAxis	0
#endif
#ifdef fFlareVertical
	#define fFlareAxis	90
#endif
        
	float3 anamFlare = AnamorphicSample(axis, coord.xy, fFlareBlur) * fFlareTint;
#ifdef fFlareHorizontal
	anamFlare += AnamorphicSample(axis, coord.xy+float2(0, 4)*FlareRadius, fFlareBlur) * fFlareTint* 0.30;
	anamFlare += AnamorphicSample(axis, coord.xy+float2(0, 3)*FlareRadius, fFlareBlur) * fFlareTint* 0.54;
	anamFlare += AnamorphicSample(axis, coord.xy+float2(0, 2)*FlareRadius, fFlareBlur) * fFlareTint* 0.72;
	anamFlare += AnamorphicSample(axis, coord.xy+float2(0, 1)*FlareRadius, fFlareBlur) * fFlareTint* 0.90;
	anamFlare += AnamorphicSample(axis, coord.xy+float2(0, -1)*FlareRadius, fFlareBlur) * fFlareTint* 0.90;
	anamFlare += AnamorphicSample(axis, coord.xy+float2(0, -2)*FlareRadius, fFlareBlur) * fFlareTint* 0.72;
	anamFlare += AnamorphicSample(axis, coord.xy+float2(0, -3)*FlareRadius, fFlareBlur) * fFlareTint* 0.54;
	anamFlare += AnamorphicSample(axis, coord.xy+float2(0, -4)*FlareRadius, fFlareBlur) * fFlareTint* 0.30;
#endif
#ifdef fFlareVertical
        anamFlare += AnamorphicSample(axis, coord.xy+float2(4, 0)*FlareRadius, fFlareBlur) * fFlareTint* 0.30;
	anamFlare += AnamorphicSample(axis, coord.xy+float2(3, 0)*FlareRadius, fFlareBlur) * fFlareTint* 0.54;
	anamFlare += AnamorphicSample(axis, coord.xy+float2(2, 0)*FlareRadius, fFlareBlur) * fFlareTint* 0.72;
	anamFlare += AnamorphicSample(axis, coord.xy+float2(1, 0)*FlareRadius, fFlareBlur) * fFlareTint* 0.90;
	anamFlare += AnamorphicSample(axis, coord.xy+float2(1, 0)*FlareRadius, fFlareBlur) * fFlareTint* 0.90;
	anamFlare += AnamorphicSample(axis, coord.xy+float2(2, 0)*FlareRadius, fFlareBlur) * fFlareTint* 0.72;
	anamFlare += AnamorphicSample(axis, coord.xy+float2(3, 0)*FlareRadius, fFlareBlur) * fFlareTint* 0.54;
	anamFlare += AnamorphicSample(axis, coord.xy+float2(4, 0)*FlareRadius, fFlareBlur) * fFlareTint* 0.30;
#endif

	res.rgb = anamFlare * fFlareIntensity;
	res.a = 1.0;
	return res;
}
#endif


#if (GODRAYS==1)
float4 PS_ProcessSunShafts(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR 
{	
	float2 texCoord = IN.txcoord;
	// Calculate vector from pixel to light source in screen space.  
    half2 deltaTexCoord = (texCoord - ScreenLightPos.xy);  
    // Divide by number of samples and scale by control factor.  
    deltaTexCoord *= 1.0f / NUM_SAMPLES * Density;  
    // Store initial sample.  
    half3 color = max(float4(0,0,0,0),tex2D(InputSampler, texCoord)-SStresh);  
	// Set up illumination decay factor.  
	half illuminationDecay = 1.0f;  
	// Evaluate summation from Equation 3 NUM_SAMPLES iterations.  
	for (int i = 0; i < NUM_SAMPLES; i++)  
	{  
		// Step sample location along ray.  
		texCoord -= deltaTexCoord;  
		// Retrieve sample at new location.  
	    half3 sample = max(float4(0,0,0,0),tex2D(InputSampler, texCoord)-SStresh);  
		// Apply sample attenuation scale/decay factors.  

#ifdef TINTCOLOR
                sample.r *= REDAMOUNT;
		sample.g *= GREENAMOUNT;
		sample.b *= BLUEAMOUNT;
#endif

#ifdef COLORING
sample = dot(sample, float3(0.3, 0.59, 0.11));
                sample.r *= REDAMOUNT;
		sample.g *= GREENAMOUNT;
		sample.b *= BLUEAMOUNT;
#endif

		sample *= illuminationDecay * Weight;  
		// Accumulate combined color.  
		color += sample;  
		// Update exponential decay factor.  
		illuminationDecay *= Decay;  
	}
	// Output final color with a further scale control factor.  
	return float4( saturate(color*SunExposure) , color.x);
}
#endif


float4 Vignettes(VS_OUTPUT_POST i, float2 vPos : VPOS) : COLOR
{

    float4 color = tex2D(InputSampler, i.txcoord);




#if (BORISVIGNETTE==1)
        float2	uv=(i.txcoord-0.5)*EVignetteRadius;
	float	vignetteold=saturate(dot(uv.xy, uv.xy));
	vignetteold=pow(vignetteold, EVignetteCurve);
	#if (VIGNCOLORING==1)
	float3	EVignetteColor=float3(VIGNREDAMOUNT, VIGNGREENAMOUNT, VIGNBLUEAMOUNT);
	#else
	float3	EVignetteColor=float3(0.0, 0.0, 0.0);
	#endif
	color.xyz=lerp(color.xyz, EVignetteColor, vignetteold*EVignetteAmount);
#endif

#if (HD6_VIGNETTE==1)
float rovigpwr = CircularPower; //for a circular vignette
	float2 sqvigpwr = float2( SquareTop, SquareBottom ); // for the top and bottom of the screen
	float vsatstrength = ColorDistortion; // color distortion
	float vignettepow = ContrastSharpen; // increases the contrast and sharpness
	float vstrengthatnight = VignetteBorder;
 
 	float2 inTex = i.txcoord;
 	float vhnd = 0.5;
 	float4 voriginal = color;
 	float4 vcolor = voriginal;
 	vcolor.xyz=1;
 	inTex -= 0.5; // center
 	inTex.y += 0.01; // offset from the center
 	float vignette = 1.0 - dot( inTex, inTex );
 	vcolor *= pow( vignette, vignettepow );
 
 	float4 rvigtex = vcolor;
 	rvigtex.xyz = pow( vcolor, 1 );
 	rvigtex.xyz = lerp(float3(0.5, 0.5, 0.5), rvigtex.xyz, 2.25); // contrast
 	rvigtex.xyz = lerp(float3(1,1,1),rvigtex.xyz,rovigpwr); // strength of the circular vinetty
 
//darken the top and bottom
 	float4 vigtex = vcolor;
 	vcolor.xyz = float3(1,1,1);

#if (LEFTANDRIGHT==1)
 	float3 topv = min((inTex.x+0.5)*2,1.5) * 2; // top
 	float3 botv = min(((0-inTex.x)+0.5)*2,1.5) * 2; // botton
	topv= lerp(float3(1,1,1), topv, sqvigpwr.x);
 	botv= lerp(float3(1,1,1), botv, sqvigpwr.y);
	vigtex.xyz = (topv)*(botv);
#endif
#if (TOPANDBOTTOM==1)
        float3 topv = min((inTex.y+0.5)*2,1.5) * 2; // top
 	float3 botv = min(((0-inTex.y)+0.5)*2,1.5) * 2; // botton
	topv= lerp(float3(1,1,1), topv, sqvigpwr.x);
 	botv= lerp(float3(1,1,1), botv, sqvigpwr.y);
	vigtex.xyz = (topv)*(botv);
#endif
#if (CORNERDARKEN==1)
	float3 rightv = min((inTex.x+0.5)*2,1.5) * 2;
 	float3 leftv = min(((0-inTex.x)+0.5)*2,1.5) * 2; 
        float3 topv = min((inTex.y+0.5)*2,1.5) * 2; 
 	float3 botv = min(((0-inTex.y)+0.5)*2,1.5) * 2; 
 	rightv= lerp(float3(1,1,1), rightv, sqvigpwr.y);
 	leftv= lerp(float3(1,1,1), leftv, sqvigpwr.x);
        topv= lerp(float3(1,1,1), topv, sqvigpwr.x);
 	botv= lerp(float3(1,1,1), botv, sqvigpwr.y);
 	vigtex.xyz = (topv)*(botv)*(rightv)*(leftv);
#endif
 	
 	
 	//vigtex.xyz = lerp(float3(1,1,1),vigtex.xyz,sqvigpwr); // strength of the top and bottom
 
 // mix the two types of vignettes
 	vigtex.xyz*=rvigtex.xyz;
	vigtex.xyz = lerp(vigtex.xyz,float3(1,1,1),(vhnd-vstrengthatnight*vhnd)); //for a dark screen
 	vigtex.xyz = min(vigtex.xyz,1);
 	vigtex.xyz = max(vigtex.xyz,0);
 	float3 vtintensity = dot(voriginal.xyz, float3(0.2125, 0.7154, 0.0721));
 	color.xyz = lerp(vtintensity, voriginal.xyz, ((((1-(vigtex.xyz*2))+2)-1)*vsatstrength)+1 );
  	color.xyz *= (vigtex.xyz);
#endif



float screenwidth = ScreenSize.x;
float screenheight = FlipSize;


#define BUFFER_RCP_WIDTH (1.0 / screenwidth)
#define BUFFER_RCP_HEIGHT (1.0 / screenheight)

#define px BUFFER_RCP_WIDTH
#define py BUFFER_RCP_HEIGHT
#define pixel float2(px,py)

#if (BORDER==1)
float2 distancefromcenter = abs(i.txcoord.xy - 0.5);
bool2 screen_border = step(0.5 - pixel,distancefromcenter);
color.xyz = (!dot(screen_border, 1.0)) ? color.xyz : 0.0;
#endif

#if (USE_DITHER==1)
float screen_size = ScreenSize.x; 
float dither_size = 2.0;  //move to settings?
float dither_bit  = 8.0;  //move to settings?
float grid_position = frac(dot(i.txcoord,(screen_size / dither_size)) + (0.5 / dither_size)); 
float dither_shift = (0.25) * (1.0 / (pow(2,dither_bit) - 1.0));
float3 dither_shift_RGB = float3(dither_shift, -dither_shift, dither_shift);
//color.xyz += lerp(2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position); 
color.rgb += dither_shift_RGB;
#endif


#if (NOISE==1)
float2 Xcoord = i.txcoord.xy;
color.rgb += tex2D(SamplerNoise, Xcoord.xy * 1024).rgb * Grain(float3(Xcoord.xy, SEEDX));
#endif


#if (SPLITSCREEN==1)
return (i.txcoord.x < 0.5) ? tex2D(InputSampler, i.txcoord) : color;
#endif

color.w = 1.0;

return  color;

}



//--------------------------------------------------------------------------------------
// Compiler
//--------------------------------------------------------------------------------------

#if (FXAA==1)
technique PostProcess
{
pass P0
{
VertexShader = compile vs_3_0 VS_PostProcess();
PixelShader = compile ps_3_0 FxaaPixelShader();

FogEnable=FALSE;
ALPHATESTENABLE=FALSE;
SEPARATEALPHABLENDENABLE=FALSE;
AlphaBlendEnable=FALSE;
FogEnable=FALSE;
SRGBWRITEENABLE=FALSE;
}
}

technique PostProcess2
{
pass P0
{
VertexShader = compile vs_3_0 VS_PostProcess();
PixelShader = compile ps_3_0 FxaaPixelShader();

FogEnable=FALSE;
ALPHATESTENABLE=FALSE;
SEPARATEALPHABLENDENABLE=FALSE;
AlphaBlendEnable=FALSE;
FogEnable=FALSE;
SRGBWRITEENABLE=FALSE;
}
}

technique PostProcess3
{
pass P0
{
VertexShader = compile vs_3_0 VS_PostProcess();
PixelShader = compile ps_3_0 FxaaPixelShader();

FogEnable=FALSE;
ALPHATESTENABLE=FALSE;
SEPARATEALPHABLENDENABLE=FALSE;
AlphaBlendEnable=FALSE;
FogEnable=FALSE;
SRGBWRITEENABLE=FALSE;
}
}

technique PostProcess4
{
pass P0
{
VertexShader = compile vs_3_0 VS_PostProcess();
PixelShader = compile ps_3_0 FxaaPixelShader();

FogEnable=FALSE;
ALPHATESTENABLE=FALSE;
SEPARATEALPHABLENDENABLE=FALSE;
AlphaBlendEnable=FALSE;
FogEnable=FALSE;
SRGBWRITEENABLE=FALSE;
}
}







technique PostProcess5
{
    pass P0
    {
 VertexShader = compile vs_3_0 VS_PostProcess();
 PixelShader  = compile ps_3_0 Tonemap();


 ZEnable=FALSE;
 CullMode=NONE;
 ALPHATESTENABLE=FALSE;
 SEPARATEALPHABLENDENABLE=FALSE;
 AlphaBlendEnable=FALSE;
 FogEnable=FALSE;
 SRGBWRITEENABLE=FALSE;
 }
}

#if (DOF==1)
technique PostProcess6
{	
	pass P0
	{
		VertexShader = compile vs_3_0 VS_PostProcess();
		PixelShader  = compile ps_3_0 PS_ProcessDoFBokeh();
	}
}
#endif


#if (DOF==1)
technique PostProcess7
#endif
#if (DOF==0)
technique PostProcess6
#endif
{
    pass P0
    {
 VertexShader = compile vs_3_0 VS_PostProcess();
 PixelShader  = compile ps_3_0 Flares();

DitherEnable=FALSE;
ZEnable=FALSE;
CullMode=NONE;
ALPHATESTENABLE=FALSE;
SEPARATEALPHABLENDENABLE=FALSE;
AlphaBlendEnable=FALSE;
StencilEnable=FALSE;
FogEnable=FALSE;
SRGBWRITEENABLE=FALSE;
 }



#if (MATSO_FLARE==1)
        pass P1
        {
                AlphaBlendEnable = true;
                SrcBlend = One;
                DestBlend = One;
                               
                PixelShader = compile ps_3_0 PS_ProcessPass_Anamorphic(fFlareAxis);
         }
#endif
#if (GODRAYS==1)
	pass P2
	{
		VertexShader = compile vs_3_0 VS_PostProcess();
		PixelShader  = compile ps_3_0 PS_ProcessSunShafts();
		AlphaBlendEnable=True;
		SrcBlend = One;
		DestBlend = One;
	}
#endif
}


#if (DOF==1)
technique PostProcess8
#endif
#if (DOF==0)
technique PostProcess7
#endif
{	
	pass P0
	{
		VertexShader = compile vs_3_0 VS_PostProcess();
		PixelShader  = compile ps_3_0 Vignettes();
	}
}
#endif

#if (FXAA==0)
technique PostProcess
{
    pass P0
    {
 VertexShader = compile vs_3_0 VS_PostProcess();
 PixelShader  = compile ps_3_0 Tonemap();


 ZEnable=FALSE;
 CullMode=NONE;
 ALPHATESTENABLE=FALSE;
 SEPARATEALPHABLENDENABLE=FALSE;
 AlphaBlendEnable=FALSE;
 FogEnable=FALSE;
 SRGBWRITEENABLE=FALSE;
 }
}

#if (DOF==1)
technique PostProcess2
{	
	pass P0
	{
		VertexShader = compile vs_3_0 VS_PostProcess();
		PixelShader  = compile ps_3_0 PS_ProcessDoFBokeh();
	}
}
#endif


#if (DOF==1)
technique PostProcess3
#endif
#if (DOF==0)
technique PostProcess2
#endif
{
    pass P0
    {
 VertexShader = compile vs_3_0 VS_PostProcess();
 PixelShader  = compile ps_3_0 Flares();

DitherEnable=FALSE;
ZEnable=FALSE;
CullMode=NONE;
ALPHATESTENABLE=FALSE;
SEPARATEALPHABLENDENABLE=FALSE;
AlphaBlendEnable=FALSE;
StencilEnable=FALSE;
FogEnable=FALSE;
SRGBWRITEENABLE=FALSE;
 }



#if (MATSO_FLARE==1)
        pass P1
        {
                AlphaBlendEnable = true;
                SrcBlend = One;
                DestBlend = One;
                               
                PixelShader = compile ps_3_0 PS_ProcessPass_Anamorphic(fFlareAxis);
         }
#endif
#if (GODRAYS==1)
	pass P2
	{
		VertexShader = compile vs_3_0 VS_PostProcess();
		PixelShader  = compile ps_3_0 PS_ProcessSunShafts();
		AlphaBlendEnable=True;
		SrcBlend = One;
		DestBlend = One;
	}
#endif
}


#if (DOF==1)
technique PostProcess4
#endif
#if (DOF==0)
technique PostProcess3
#endif
{	
	pass P0
	{
		VertexShader = compile vs_3_0 VS_PostProcess();
		PixelShader  = compile ps_3_0 Vignettes();
	}
}
#endif